﻿using NewsPortal.DataAccess.Abstraction;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewsPortal.DataAccess
{
    public class SqlUnitOfWork<T>: IUnitOfWork<T> where T: class, IEntity
    {
        private ApplicationDbContext _context;
        public SqlUnitOfWork(ApplicationDbContext context)
        {
            this._context = context;
        }

        public IRepository<T> Repository
        {
            get { return new SqlRepository<T>(_context); }
        }

        public IRepository<TEntity> GetTypeRepository<TEntity>() where TEntity : class, IEntity
        {
            return new SqlRepository<TEntity>(_context);
        }

        public int SaveChanges()
        {
            return _context.SaveChanges();
        }

        public Task<int> SaveChangesAsync()
        {
            return _context.SaveChangesAsync();
        }
    }
}
